package edu.tapestry.iddb.client.helpers;

import iddb.MessagePOJO;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataStorage {

	List<PI> pluginsIdents;
	
	Map<PI, PluginsMessages> messagesMap;
	

	public DataStorage(){
		this.pluginsIdents = new ArrayList<PI>();
		this.messagesMap = new HashMap<PI, PluginsMessages>();
	}
	
	public void addPluginIdent(PI ident){
		this.pluginsIdents.add(ident);
	}
	
	public List<PI> getConnectedPluginsIdents() {
		return pluginsIdents;
	}

	public List<MessagePOJO> getMessages(PI ident, String sender){
		PluginsMessages pm = this.messagesMap.get(ident);
		if (pm == null){
			return new ArrayList<MessagePOJO>();
		}
		
		List<MessagePOJO> list = pm.getMessages(sender);
		return list;
	}
	
	public void addMessages(PI ident, List<MessagePOJO> pojos){
	
		PluginsMessages pm; 
		
		if (this.messagesMap.containsKey(ident)){
			pm = this.messagesMap.get(ident);
		}
		else{
			pm = new PluginsMessages();
		}
		
		pm.addMessage(pojos);
		
		this.messagesMap.put(ident, pm);
	}

	
	
	
	
}
